package com.amayadream.webchat.controller;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

import com.amayadream.webchat.pojo.ChatRecord;
import com.amayadream.webchat.service.IChatRecordService;

/**
 * 聊天记录查询控制类
 * */	


@Controller
@RequestMapping(value = "")
public class recordController {
	 @Resource 
	 private IChatRecordService IChatRecordservice;
	 @RequestMapping(value = "{userid}/records")
	    public ModelAndView selectAll(@PathVariable("userid") String userid, @RequestParam(defaultValue = "1") int page) {
	        int pageSize = 5;
	        ModelAndView views = new ModelAndView("records");
	       
	        
	        List<ChatRecord> listFromID = IChatRecordservice.selectByFromid(userid, page, pageSize);
	        List<ChatRecord> listToID = IChatRecordservice.selectByToid(userid, page, pageSize);
	        int countFromID = IChatRecordservice.selectCountByFromid(userid, pageSize);
	        int countToID = IChatRecordservice.selectCountByToid(userid, pageSize);;
	        views.addObject("listFromID", listFromID);
	        views.addObject("listToID", listToID);
	        views.addObject("countFromID", countFromID);
	        views.addObject("countToID", countToID);
	        return views;
	    }
}
